display('0.Kerbol, 1.Kerbin, 2.Moho, 3.Eve, 4.Duna, 5.Dres, 6.Jool, 7.Eeloo, 8.Gilly, 9.Mun, 10.Minmus, 11.Ike, 12.Laythe, 13.Vall, 14.Tylo, 15.Bop, 16.Pol')
Target=input('Target=');
targnam=['Kerbol';'Kerbin';'Moho  ';'Eve   ';'Duna  ';'Dres  ';'Jool  ';'Eeloo ';'Gilly ';'Mun   ';'Minmus';'Ike   ';'Laythe';'Vall  ';'Tylo  ';'Bop   ';'Pol   '];
format long g;
Radius=[261600000,600000,250000,700000,320000,138000,6000000,210000,13000,200000,60000,130000,500000,300000,600000,65000,44000];
r=Radius(Target+1);
o=input('Planned Orbit Height=(m)');
n=round(input('Satellite Count='));
a1=nthroot(power((n-1)/n,2)*power(o+r,3),3);
h11=2*a1-o-2*r;
h12=o;
a2=nthroot(power((n+1)/n,2)*power(o+r,3),3);
h21=o;
h22=2*a2-o-2*r;
h=[h11,h21;h12,h22]
t=[0:2*pi/400:2*pi];
x=(o+r)*cos(t);
y=(o+r)*sin(t);
xm=max(x);
ym=max(y);
xn=min(x);
yn=min(y);
plot(y,x,'b');
hold on;
b1=sqrt(a1^2-(r-a1+o)^2);
x=a1-o-r+a1*cos(t);
y=b1*sin(t);
xm=max(max(x),xm);
ym=max(max(y),ym);
xn=min(min(x),xn);
yn=min(min(y),yn);
plot(y,x,'r');
b2=sqrt(a2^2-(a2-o-r)^2);
x=a2-o-r+a2*cos(t);
y=b2*sin(t);
xm=max(max(x),xm);
ym=max(max(y),ym);
xn=min(min(x),xn);
yn=min(min(y),yn);
ym=max(y);
yn=min(y);
plot(y,x,'g');
plot(0,0,'+');
text(0,o+r,['Planned height: ',num2str(o),'m']);
text(0,2*a1-o-r,['Quick and low, Pe: ',num2str(h11),'m']);
text(0,2*a2-o-r,['Slow and high, Ap: ',num2str(h22),'m']);
text(0,-o-r,'Satelite Deploy!');
text(0,0,targnam(Target+1,:));
plot([0,0,0,0],[o+r,-o-r,2*a1-o-r,2*a2-o-r],'x');
xm=xm*1.1;
ym=ym*1.1;
yn=yn*1.1;
xn=xn*1.1;
plot([ym,yn,0,0],[0,0,xm,xn],'.');
hold off;
title('Orbit resonance planning schemetic diagram')
axis equal;
ext=input('Job done, press enter to exit, wish you enjoy KSP!');
exit();
